package com.yuzhyn.hiops.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yuzhyn.hiops.common.entity.Tables;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface DbMapper extends BaseMapper {

    @Select("${sql}")
    List<Map> query(@Param("sql") String sql);

    @Select("create table ${tableName}( id varchar constraint ${tableName}_pk primary key);")
    void createTable(@Param("tableName") String tableName);

    @Select("alter table ${tableName} add ${columnName} ${columnType};")
    void addColumn(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("columnType") String columnType);

    @Select("SELECT * FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('mysql','information_schema','performance_schema')")
    List<Tables> getTables();

    @Select("SELECT COUNT(1) FROM ${schemaName}.${tableName}")
    List<Tables> getTableRowCount();
}
